function postData() {
    // Function to handle form submission
    const handleSubmit = (event) => {
        event.preventDefault();
        // Get the form input values
        const name = document.getElementById('nameInput').value;
        const distance = document.getElementById('distanceInput').value;
        const location = document.getElementById('locationInput').value;
        const difficulty = document.getElementById('difficultyInput').value;

        // Create an object with the new hike data
        const newHike = {
            name: name,
            distance: distance,
            location: location,
            difficulty: difficulty,
        };
        // Check if the hikes object exists in local storage
        let hikes = localStorage.getItem('hikes');
        if (!hikes) {
            // Create a new hikes object if it doesn't exist
            hikes = {
                "hikes": []
            };
        } else {
            hikes = JSON.parse(hikes);
        }
        // Add the new hike to the hikes object
        hikes.hikes.push(newHike);
        // Save the updated hikes object to local storage
        localStorage.setItem('hikes', JSON.stringify(hikes));
        // Redirect to main.html
        window.location.href = 'main.html';
    };
    // Add event listener to the form submit event
    const form = document.getElementById('newHikeForm');
    form.addEventListener('submit', handleSubmit);
}
postData();